package cn.ekuma.android.driver;

import java.io.IOException;
import java.io.OutputStream;

import android.bluetooth.BluetoothDevice;
import cn.ekuma.android.bluetooth .BluetoothRfcommClient;

import com.openbravo.pos.printer.TicketPrinterException;
import com.openbravo.pos.printer.escpos.PrinterWritter;

public class PrinterWritterBluetooth extends PrinterWritter /* implements SerialPortEventListener */ {
    

    private OutputStream m_out;
    
    BluetoothRfcommClient client;
    
    /** Creates a new instance of PrinterWritterComm */
    public PrinterWritterBluetooth(BluetoothRfcommClient client,BluetoothDevice device) throws TicketPrinterException {
    	this.client=client;
    	client.connect(device);
    }

	protected void internalWrite(byte[] data) {
		client.write(data);
    }
    
    protected void internalFlush() {
        try {  
            if (m_out != null) {
                m_out.flush();
            }
        } catch (IOException e) {
            System.err.println(e);
        }    
    }
    
    protected void internalClose() {
        try {  
            if (m_out != null) {
                m_out.flush();
                m_out.close();
                m_out = null;
                client.stop();
            }
        } catch (IOException e) {
            System.err.println(e);
        }    
    }
}
